import React, { useEffect, useState, useCallback } from 'react'
import teacherApi from '../../../api/teacher/index';
// import from '../../api/subject/'
import { Table, Popconfirm, Button, message, } from 'antd';
import { connect } from 'dva';
function Teacher() {
    useEffect(() => {
        getData({});
    }, [getData])
    const getData = useCallback(async (val) => {
        console.log(232323, val);
        const { data } = await teacherApi.getTeacherListApi(val);
        console.log(data, '获取回的数据');
        setList([...data.records]);
        setPaging({
            ...paging,
            current: data.current,
            pageSize: data.size,
            total: data.total,
        });
    }, [paging])
    const [list, setList] = useState([

    ])
    const columns = [
        {
            title: "id",
            dataIndex: 'id',
            key: 'id',
        },
        {
            title: "教师姓名",
            dataIndex: 'name',
            key: 'name',
        },

        {
            title: "工作经历",
            dataIndex: 'career',
            key: 'career',
        },

        {
            title: "教育经历",
            dataIndex: 'education',
            key: 'education',
        },

        {
            title: "头像",
            dataIndex: 'avatar',
            key: 'avatar',
        },
        {
            title: "是否名师",
            dataIndex: 'isFamous',
            key: 'isFamous',
        },

        {
            title: "状态",
            dataIndex: 'status',
            key: 'status',
        },
        {
            title: '擅长科目',
            dataIndex: 'subjectId',
            key: 'subjectId',
        },

        {
            title: '操作',
            key: 'modify',
            render: (record) => (//record当前对象
                <Popconfirm
                    title="你确定要删除这条数据吗?"
                    onConfirm={() => delUsers(record.id)}
                    onCancel={cancel}
                    okText="确认删除"
                    cancelText="取消删除"
                >
                    <Button size='small' type='primary'>删除</Button>
                </Popconfirm>
            ),
        },
    ];
    async function delUsers(record) {
        console.log('6', record);
        const { data } = await teacherApi.delTeacherApi(record);
        console.log(data);
        if (data.code === 200) {
            message.success('删除成功');
        } else {
            message.error('删除失败');

        }
        getData(1);

    }
    function cancel() {
        message.info('取消删除');
    }
    const [paging, setPaging] = useState({
        current: 1,
        pageSize: 2,
        total: 4,
        onChange: function (params) {
            console.log('6', params);
            getData({ currentPage: params });
        }
    });

    return (
        <div>
            <Table dataSource={list} columns={columns} pagination={paging} rowKey="id" />
        </div>
    )
}
function mapStateToProps(state) {
    console.log(state);
    return (
        state
    )
}

export default connect(mapStateToProps)(Teacher);